package com.example.demo.beans;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 东莞呵呵
 * Date:2022-10-19
 * Time:21:15
 */
@Controller
public class TestController {
    //请求转发是服务器端的行为
    @RequestMapping("/fw1")
    public String myForward(){
        return "forward:/login.html";
    }
    @RequestMapping("/fw2")
    public void myForward2(HttpServletRequest req, HttpServletResponse rep) throws ServletException, IOException {
        req.getRequestDispatcher("/login.html").forward(req,rep);
    }

    @RequestMapping("/rd")
    public String myRedirect(){
        return  "redirect:/login.html";
    }
    @RequestMapping("/rd2")
    public void myRedirect2(HttpServletResponse response) throws IOException {
        response.sendRedirect("/login.html");
    }
}
